# include <iostream>
# include <vector>

using namespace std;

class Library;
class Manager;

class Visitor
{
	public:
		Visitor(Manager *t);
		virtual void visit(Library *t)=0;
};

class Library{
	public:
		Library(Manager*t);
		void accept(Visitor*t)
		{
			t->visit(this);
		}
		virtual void Do()=0;
};

class VisitorA:public Visitor{
	public:
		VisitorA(Manager *t):Visitor(t){}
		virtual void visit(Library*t)
		{
			t->Do();
		}
};

class Book:public Library{
	public:
		Book(Manager*t):Library(t){}
	
		//void accept(Visitor*t)
		//{
		//	t->visit( this);
		//}
		void Do()
		{
			cout<<"Book"<<endl;
		}
		
};

class Manager{
	private:
		vector<Library*> vl;
		vector<Visitor*> vv;
	public:
		void AddVisitor(Visitor*t)
		{
			vv.push_back(t);
		}
		void AddLibrary(Library*t)
		{
			vl.push_back(t);
		}
		void Promise()
		{
			for (vector<Visitor*>::iterator it=vv.begin();it!=vv.end();it++)
			{
				for (vector<Library*>::iterator jt=vl.begin();jt!=vl.end();jt++)
				{
					(*jt)->accept(*it);
				}
			}
		}
};

void Visitor:: visit(Library*t)
{
		t->Do(); 
}

Visitor::Visitor (Manager*t)
{
	t->AddVisitor(this);
}

Library::Library(Manager*t)
{
	t->AddLibrary(this);
}

int main(void)
{
	Manager*pm=new Manager();
	Library*pl=new Book(pm);
	Visitor*pv=new VisitorA(pm);

	pm->Promise();
	
	delete pm;
	delete pl;
	delete pv;
	
	return 0;
}
